﻿using System;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;


public class CandidateItem : MonoBehaviour
{
    public long Id;

    public NetworkImage icon;

    public Text nameText;
    public Text idVerifyText;
    public Image idVerifyBg;
    public Text location;
    public Text hometown;
    public Text ageText;
    public Text jobText;
    public Text eduText;
    public Text heightText;

    Action<CandidateItem> m_OnClick;

    public Color verifyActiveColor;
    public Color verifyDisactiveColor;

    void Awake()
    {

    }
    internal void Init(UserInfo UserInfo, Action<CandidateItem> onSelect)
    {
        this.Id = UserInfo.userId; 
        m_OnClick = onSelect;

        InitUI(UserInfo);
        //RefreshMsg(skin.result);

    }

    void OnEnable()
    {
        StartCoroutine(UnityFunctions.AdjustItemsLayout(transform));
    }

    void InitUI(UserInfo userInfo)
    {
        nameText.text = userInfo.name;
        if (userInfo.realNameVerify)
        {
            idVerifyText.text = "已认证";
            idVerifyBg.color = verifyActiveColor;
        }
        else
        {
            idVerifyText.text = "未认证";
            idVerifyBg.color = verifyDisactiveColor;
        }
        ageText.text = (userInfo.birthYear % 1900)+"年";
        jobText.text = userInfo.job;
        location.text = "现居"+userInfo.locationProvince + userInfo.locationCity;
        hometown.text = userInfo.hometownProvince.Replace("省", "") + userInfo.hometownCity.Replace("市", "") + "人";
        eduText.text = DataString.GetEducationString(userInfo.eduation);
        heightText.text = DataString.GetHeightString(userInfo.height);

        icon.Init(userInfo.icon);
    }

    //public void RefreshMsg(int result,string refuseCause = "")
    //{
    //    if (result <= 0)
    //    {
    //        msgText.gameObject.SetActive(false);
    //    }
    //    else
    //    {
    //        if (result == Apply.ApplyResult_Suc)
    //        {
    //            ShowMsg("Successfully apply!", sucColor);
    //        }
    //        else  if (result == Apply.ApplyResult_Fail)
    //        {
    //            if(string.IsNullOrEmpty(refuseCause))
    //                ShowMsg($"It was refused", failColor);
    //            else 
    //                ShowMsg($"It was refused \nreason:{refuseCause}", failColor);
    //        }
    //        else
    //        {
    //            ShowMsg("Waiting for response...", normalColor);
    //        }
    //    }
    //}
   
    public void OnClick()
    {
        m_OnClick?.Invoke(this);
    }

    //void ShowMsg(string msg,Color color)
    //{
    //    msgText.color = color;
    //    msgText.gameObject.SetActive(true);
    //    msgText.text = msg;
    //}

    internal void UpdateCandidate(UserInfo skin)
    {
        InitUI(skin);

        //if (lockImg)
        //    lockImg.SetActive(!skin.unlock);

        //priceText.transform.parent.gameObject.SetActive(false);
    }

}
